package hero.antlr;

import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.tree.CommonTree;


public class Test2 {

    public static void main(String[] args) {
        test2();
    }

    public static void test2() {
        try {

            ANTLRFileStream fs = new ANTLRFileStream("test.txt");
            SimplestLexer lex = new SimplestLexer(fs);
            CommonTokenStream tokens = new CommonTokenStream(lex);
            SimplestParser parser = new SimplestParser(tokens);
            parser.prog();
            
        } catch (Throwable e) {
            e.printStackTrace();
        }
        
    }

    public static void printTree(CommonTree t, int indent) {
        if ( t != null ) {
            StringBuffer sb = new StringBuffer(indent);
            for ( int i = 0; i < indent; i++ )
                sb = sb.append("   ");
            for ( int i = 0; i < t.getChildCount(); i++ ) {
                System.out.println(sb.toString() + t.getChild(i).toString());
                printTree((CommonTree)t.getChild(i), indent+1);
            }
        }
    }
    

}
